<?php

include_once("config.php");

function contactUser($user)
{
	$message = "It is your turn to draft.  Go to fff.hostoi.com to pick a player!";
	if (isset($user->pCode))
	{
		return textToUser($user->cCode, $user->number, $user->pCode, $message);
	}
	else
	{
		$subject = "Its Your Turn!";
		return mailToUser($user->email, $subject, $message);
	}
}

function mailToUser($to, $subject, $message)
{
	$from = "admin@fff.hostoi.com";
	$headers = "From:" . $from;
	mail($to,$subject,$message,$headers);
	return true;
}

function mailToAllUsers($users, $selection)
{
	foreach ($users as $u)
	{
		$message = "".$selection;
		if (isset($u->pCode))
		{
			textToUser($u->cCode, $u->number, $u->pCode, $message); 
		}
		else
		{
			$to = $u->email;
			$subject = "New Selection Was Made";
			mailToUser($to, $subject, $message);
		}
	}
}

function getTo($cCode, $number, $pCode)
{
	if ($pCode == "att")
	{
		return $number."@txt.att.net";
	}
	else if ($pCode == "ver")
	{
		return $number."@vtext.com";
	}
	else if ($pCode == "spr")
	{
		return $cCode.$number."@messaging.sprintpcs.com";
	}
	else
	{
		return false;
	}
}

function textToUser($cCode, $number, $pCode, $message)
{
	$to = getTo($cCode, $number, $pCode);
	$subject = "";
	mailToUser($to, $subject, $message);
}
?> 